package util;


import java.sql.*;

public class JDBCTest {
    public static void main(String[] args) {
        String url1 = "jdbc:mysql://localhost:3306/atm?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
        String url2 = "jdbc:mysql://127.0.0.1:3306/atm?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
        Connection connection = null;
        PreparedStatement statement = null;
        ResultSet resultSet = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection = DriverManager.getConnection(url2,"root","lyt958524377394");
            statement = connection.prepareStatement("select * from goods");
            resultSet = statement.executeQuery();
            while (resultSet.next()){
                System.out.println("id:"+resultSet.getInt("id"));
//                System.out.println("name:"+resultSet.getString("name"));
//                System.out.println("sex:"+resultSet.getString("sex"));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        finally {
            if(null!=resultSet){
                try {
                    resultSet.close();
                } catch (SQLException exception) {
                    exception.printStackTrace();
                }
            }
            if(null!=statement){
                try {
                    statement.close();
                } catch (SQLException exception) {
                    exception.printStackTrace();
                }
            }
            if(null!=connection){
                try {
                    connection.close();
                } catch (SQLException exception) {
                    exception.printStackTrace();
                }
            }
        }
    }
}

